﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicServer.Users;
using Model;

namespace BugSysSolution.RequestAjaxPage
{
    public partial class UserAjaxPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String tag = Request["tag"] ?? String.Empty;
            if (tag == "checkuid")
            {
                CheckExist();
            }
            if (tag == "adduser")
            {
                AddUser();
            }
        }

        public void CheckExist()
        {
            String uid = Request.Form["uid"].ToLower();
            UserLogic ul = new UserLogic();
            Users user = ul.GetUserByUid(uid);
            if (user == null)
            {
                Response.Write("0|通过");
            }
            else
            {
                Response.Write("1|已存在");
            }
        }

        public void AddUser() 
        {
            UserLogic ul = new UserLogic();
            Users user = new Users();
            user.Uid = Request.Form["uid"].ToLower();
            user.PassWord = Request.Form["PassWord"].ToString();
            user.Email = Request.Form["Email"].ToString();
            user.QQ = Request.Form["QQ"].ToString() == "" ? 0 : Convert.ToInt32(Request.Form["QQ"].ToString());
            user.RealName = Request.Form["RealName"].ToString();

            int result = ul.AddUser(user);
            if (result != 1)
            {
                Response.Write("1|添加失败");
            }
            else
            {
                Response.Write("0|添加成功");
            }
        }
    }
}